/* 查看人工组卷 */
import React, { PureComponent } from 'react';
import { Form, Button, Input, Radio, InputNumber, Row, Col, Card, List } from 'antd';
import { HardLevelSelect, ExamSubjectTreeSelect, RelatedPersonnelextendsTransfer ,PaperTemplate} from '../Components/AntComponents'
import { PageContainer } from '@ant-design/pro-layout';
import { getPaperDetail } from '@/services/paperInfo'
import { isLianxi } from '@/utils/utils'
const layout = {
    labelCol: { span: 2 },
    wrapperCol: { span: 15 },
};
const tailLayout = {
    wrapperCol: { offset: 1 },
};
export default class Index extends PureComponent<any, any> {
    constructor(props: any) {
        super(props)
        this.state = {
            name: '',
            ruleSubctData: [],
            subject: [],
            template: null,
            complexity: '0',
            total: 0,
            test_type: '2',
            multiple: 0,
            multiple_num: 0,
            multiple_deduct: 0,
            multiple_mistake: 0,
            choices: 0,
            choices_num: 0,
            choices_deduct: 0,
            choices_mistake: 0,
            judge: 0,
            judge_num: 0,
            judge_deduct: 0,
            judge_mistake: 0,
            test_time: 0,
            badStart: 0,
            badEnd: 0,
            sosoStart: 0,
            sosoEnd: 0,
            goodStart: 0,
            goodEnd: 0,
            wonderfulStart: 0,
            wonderfulEnd: 0,
            people: [],
            ruleWay: '1',
            rules: [],
            ruleType: '0',
            ruleSubject: null,
            ruleHardLevel: '0',
            ruleQuestionNum: null,
            ruleSubjectLabel: null,
            ruleHardLevelLabel: null,
            ruleTypeLabel: null,
            loading: false,
            subject_num: '',
        }
    }
    componentDidMount() {
        const id = this.props.match.params.id;
        getPaperDetail({ id }).then(res => {
            const {
                choices_deduct, choices_mistake, choices_num, choices_score, complexity, excellent, fail,
                good, judge_deduct, judge_mistake, judge_num, judge_score, multiple_deduct,
                multiple_mistake, multiple_num, multiple_score, name, pass, people, subjects,
                selection_rules, subject, template, test_time, test_type, total, selection_ruless
            } = res;
            const badData = fail ? fail.split(',') : [];
            const sosoData = pass ? pass.split(',') : [];
            const goodData = good ? good.split(',') : '';
            const wonderfulData = excellent ? excellent.split(',') : '';
            const subjectData = subject.split(',').map(Number)
            const subjectsData = subjects.split(',')
            const ruleSubctData = []
            for (let i = 0; i < subjectData.length; i++) {
                ruleSubctData.push({ key: subjectData[i], title: subjectsData[i] })
            }
            this.setState({
                multiple: multiple_num, multiple_num: multiple_score, multiple_deduct, multiple_mistake,
                judge: judge_num, judge_num: judge_score, judge_deduct, judge_mistake,
                choices: choices_num, choices_num: choices_score, choices_deduct, choices_mistake,
                complexity: complexity + '', badStart: badData[0], badEnd: badData[1], sosoStart: sosoData[0], sosoEnd: sosoData[1],
                goodStart: goodData[0], goodEnd: goodData[1], wonderfulStart: wonderfulData[0], wonderfulEnd: wonderfulData[1],
                name, template, people: people ? people.split(',').map(Number) : [], subject: subjectData, test_time, test_type: test_type + '', total,
                ruleWay: selection_rules + '', rules: selection_ruless, ruleSubctData
            })
        })
    }
    goBack = () => {
        history.back()
    }
    render() {
        const { rules, ruleWay, test_type, people, total, template,
            complexity, subject, multiple, multiple_num, multiple_deduct, multiple_mistake,
            choices, choices_num, choices_deduct, choices_mistake,
            judge, judge_num, judge_deduct, judge_mistake, test_time, loading,
            badStart, badEnd, sosoEnd, sosoStart, goodEnd, goodStart, wonderfulEnd, wonderfulStart, name } = this.state;
        const renderType = (question: number) => {
            switch (question) {
                case 1:
                    return '单选';
                case 2:
                    return '全选';
                case 3:
                    return '判断';
                default:
                    return '全部';
            }
        }
        const renderComplexity = (complexity: number) => {
            switch (complexity) {
                case 1:
                    return '容易';
                case 2:
                    return '较易';
                case 3:
                    return '中等';
                case 3:
                    return '较难';
                case 3:
                    return '难';
                default:
                    return '全部';
            }
        }
        return (
            <PageContainer title="查看随机组卷">
                <Card>
                    <Form>
                        <Form.Item {...layout} label="考试名称">
                            <Input style={{ width: 200 }} placeholder="请输入考试名称" value={name} ></Input>
                        </Form.Item>
                        <Form.Item {...layout} label="考试科目">
                            <ExamSubjectTreeSelect value={subject} />
                        </Form.Item>
                        <Form.Item {...layout} label="试卷模板">
                            <PaperTemplate value={template} />
                        </Form.Item>
                        <Form.Item {...layout} label="难易程度">
                            <HardLevelSelect value={complexity} />
                        </Form.Item>
                        <Form.Item {...layout} label="试卷总分">
                            <InputNumber placeholder="请输入试卷总分" style={{ width: 200 }} value={total} />
                        </Form.Item>
                        <Form.Item {...layout} label="试卷类别">
                            <Radio.Group value={test_type}>
                                <Radio value="2">模拟考试试卷</Radio>
                                <Radio value="1">正式考试试卷</Radio>
                            </Radio.Group>
                        </Form.Item>
                        <Form.Item {...layout} label="试题分布">
                            <Row>
                                <Col style={{ marginBottom: 10 }} span={6}>单选题 <InputNumber value={multiple} /> 道</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>每题 <InputNumber value={multiple_num} /> 分</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>未答扣 <InputNumber value={multiple_deduct} /> 分</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>答错扣 <InputNumber value={multiple_mistake} /> 分</Col>
                            </Row>
                            {
                                !isLianxi()&&   <Row>
                                <Col style={{ marginBottom: 10 }} span={6}>多选题 <InputNumber value={choices} /> 道</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>每题 <InputNumber value={choices_num} /> 分</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>未答扣 <InputNumber value={choices_deduct} /> 分</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>答错扣 <InputNumber value={choices_mistake} /> 分</Col>
                            </Row>
                            }
                         
                            <Row>
                                <Col style={{ marginBottom: 10 }} span={6}>判断题 <InputNumber value={judge} /> 道</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>每题 <InputNumber value={judge_num} /> 分</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>未答扣 <InputNumber value={judge_deduct} /> 分</Col>
                                <Col style={{ marginBottom: 10 }} span={6}>答错扣 <InputNumber value={judge_mistake} /> 分</Col>
                            </Row>
                        </Form.Item>
                        <Form.Item {...layout} label="考试时长">
                            <InputNumber value={test_time} style={{ width: 200 }} /> 分钟
                    </Form.Item>
                        <Form.Item {...layout} label="分值标准">
                            <Row>
                                <Col span={24} style={{ marginBottom: 10 }}><div style={{ width: 50, float: 'left' }}>不及格</div> <InputNumber value={badStart} /> —— <InputNumber value={badEnd} /> </Col>
                                <Col span={24} style={{ marginBottom: 10 }}><div style={{ width: 50, float: 'left' }}>及格</div>  <InputNumber value={sosoStart} /> —— <InputNumber value={sosoEnd} /></Col>
                                <Col span={24} style={{ marginBottom: 10 }}><div style={{ width: 50, float: 'left' }}>良好</div>  <InputNumber value={goodStart} /> —— <InputNumber value={goodEnd} /></Col>
                                <Col span={24} style={{ marginBottom: 10 }}><div style={{ width: 50, float: 'left' }}>优秀</div>  <InputNumber value={wonderfulStart} /> —— <InputNumber value={wonderfulEnd} /></Col>
                            </Row>
                        </Form.Item>

                        <Form.Item {...layout} label="抽题规则">
                            <Radio.Group value={ruleWay} >
                                <Radio key="1" value="1">系统自动生成</Radio>
                                <Radio key="2" value="2">人工自定义</Radio>
                            </Radio.Group>
                        </Form.Item>
                        {
                            ruleWay === '2' && (
                                <React.Fragment>
                                    <Form.Item {...layout} label="规则列表">
                                        <List >
                                            {rules.map((item: any, index: number) => {
                                                return (
                                                    <List.Item key={index}>
                                                        题型：{item.ruleTypeLabel || renderType(item.question)}&nbsp;&nbsp;
                                                    科目：{item.ruleSubjectLabel || item.subject}&nbsp;&nbsp;
                                                    难易程度：{item.ruleHardLevelLabel || renderComplexity(item.complexity)}&nbsp;&nbsp;
                                                    抽题数：{item.num}
                                                    </List.Item>
                                                )
                                            })}
                                        </List>
                                    </Form.Item>
                                </React.Fragment>
                            )
                        }
                        <Form.Item {...layout} label="选择补录人员">
                            <RelatedPersonnelextendsTransfer value={people} />
                        </Form.Item>
                        <Form.Item {...tailLayout}>
                            <Button onClick={this.goBack} loading={loading}>返回</Button>
                        </Form.Item>
                    </Form>
                </Card>
            </PageContainer>
        )
    }
}
